
SHELL=/bin/bash

#echo "Usage: make x64/dm6446/dm365/hi3515/x86"

include config.mk

# will be diff with diff ARCH
ARFLAGS= ra

ifeq ($(ARCH), x64)
    CFLAGS += -Ix64/include
    LDFLAGS+=-Lx64/lib
    EXTS=x64-pc
    ARFLAGS=rc
    OBJDIR=.objX64
else
ifeq ($(ARCH), dm6446)
    CFLAGS+=-Iarm/include
    LDFLAGS+=-Larm/lib
    EXTS=arm-elf
    OBJDIR=.objArm
    CROSSCOMPILE=arm_v5t_le-
else
ifeq ($(ARCH), dm365)
    CFLAGS+=-Idm365/include
    LDFLAGS+=-Ldm365/lib
    EXTS=arm-none-linux-gnueabi
    OBJDIR=.objDm365
    CROSSCOMPILE=arm-none-linux-gnueabi-
else
ifeq ($(ARCH), hi3515)
    CFLAGS+=-Ihi3515/include
    LDFLAGS+=-Lhi3515/lib
    EXTS=arm-hisi-linux
    OBJDIR=.objHi3515
    CROSSCOMPILE=arm-hisi-linux-
else
     CFLAGS+=-Ix86/include
     LDFLAGS+=-Lx86/lib
     ARFLAGS=rc
     EXTS=x86-pc
     OBJDIR=.objX86
endif
endif
endif  
endif

FILENAME=jklibs

AR=$(CROSSCOMPILE)ar
CC=$(CROSSCOMPILE)g++
STRIP=$(CROSSCOMPILE)strip

CFLAGS+=-Wall -O2 -ggdb3
LDFLAGS+=-L.libs

CFLAGS+= -Iinclude
OTHERLIBS=
LOCALLIB= -ljkprint

MAIN=jkdemo.c

LIB_OBJS=jkprint.o

OBJS=$(LIB_OBJS:%=$(OBJDIR)/%)

EXEC=bin/jkdemo-$(EXTS)
STATIC_LIB=libjkprint-$(EXTS).a

.PHONY:tags clean

CCNAME=$(shell basename $(CC))
ifneq ("$V", "1")
  Q=@
endif

all: main

main: libs $(OBJS)
	$(Q) mkdir -p bin
	$(Q) echo -e "\033[1;36m $(CC)  \t$(EXEC)\033[0m"
	$(Q) $(CC) $(CFLAGS) -o $(EXEC) $(MAIN) $(OBJS) $(LDFLAGS) $(OTHERLIBS) $(LOCALLIB)


$(OBJDIR)/%.o: src/%.c
	$(Q)mkdir -p $(OBJDIR)
	$(Q)echo -e "\033[1;35m $(CCNAME) \t$@\033[0m"
	$(Q)$(CC) -pipe $(CFLAGS) -c -o $@ $< $(LDFLAGS) $(OTHERLIBS)


libs: $(STATIC_LIB)

$(STATIC_LIB):$(OBJS)
	$(Q) mkdir -p .libs
	$(AR) $(ARFLAGS) -o .libs/$@ $^
	@ ln -sf $(STATIC_LIB) .libs/libjkprint.a


install: 

clean:
	rm $(EXEC) bin .obj* .libs $(STATIC_LIB) *.a tags -fr;

x64:
	$(Q) echo "ARCH=x64" > config.mk

x86:
	$(Q) echo "ARCH=x86" > config.mk

dm6446:
	$(Q) echo "ARCH=dm6446" > config.mk

dm365:
	$(Q) echo "ARCH=dm365" > config.mk

hi3515:
	$(Q) echo "ARCH=hi3515" > config.mk

